#pragma once
#ifndef VARTABLE_H
#define VARTABLE_H

#include "spa_types.h"
#include <string>
#include <map>

using namespace std;

enum VarType {
	INT_TYPE
	// There may be more variable data types in future!
};

class VarTable
{

public:

	VarTable();
	~VarTable();

	/*
	 Returns:
		Added successully:	Return the proc's index.
		Already exist:		Return the proc's index.
		Invalid proc name:	Return -1;
	*/
	VARINDEX InsertVar(const STRING var_name);

	/*
	 Returns:
		Variable name if var index exists in VarTable.
		Empty STRING if var index does not exist.
	*/
	STRING GetVarName(const VARINDEX index);

	/*
	 Returns:
		VARINDEX if variable exists in VarTable.
		-1 if variable does not exist.
	*/
	VARINDEX GetVarIndex(const STRING var_name);

	/*
	 Returns:
		Number of variables contained in VarTable
	*/
	INTEGER GetVarCount();

	/********************************
	      New APIs for VarTable
	*********************************/

	/*
	 Returns:
	   No variables:	An empty STRING_ARRAY if there are nothing found, i.e. size() == 0
	   Have variables:	STRING_ARRAY containing all the names of the variables.
	*/
	STRING_ARRAY GetAllVarNames();

	/*
	 Returns:
		The set of variable indices is returned if there are variables in VarTable.
		The empty set, ie. size() == 0 if are no variables in VarTable.
	*/
	VARINDEX_ARRAY GetAllVarIndex();

private:

	/*
	 There may be more information we would want to keep about a variable.
	 For example, its name, variable type (all var are integers for now), etc.
	*/
	struct VarInfo 
	{
		VARINDEX var_index;
		STRING var_name;
		int var_type;
		// expand here if we need to record more info about a variable.
	};
	
	/*
	 Will start from index 0.
	 Use this for the index of the next variable insertion.
	*/
	int curr_index;
	VARINDEX_ARRAY var_index_array;

	map<VARINDEX, VarInfo*> index_table;
	map<STRING, VarInfo*> name_table;
};

#endif